#include <iostream>
#include <curl/curl.h>

// 回调函数
size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp) 
{
    ((std::string*)userp)->append((char*)contents, size * nmemb);
    return size * nmemb;
}

int main() 
{
    CURL* curl;
    CURLcode res;
    std::string readBuffer;

    curl = curl_easy_init();
    if (curl) 
    {
        // 设置FTP URL和认证信息
        curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/update/version.txt");
        curl_easy_setopt(curl, CURLOPT_USERPWD, "user:pass");
        
        // 设置回调函数
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
        
        // 执行请求
        res = curl_easy_perform(curl);
        
        // 检查结果
        if (res != CURLE_OK) 
        {
            std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl;
        } 
        else 
        {
            std::cout << "更新信息:\n" << readBuffer << std::endl;
        }
        
        curl_easy_cleanup(curl);
    }
    return 0;
}